//
//  ZiXunViewController.swift
//  BaseSwift
//
//  Created by gh on 2019/10/15.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit

class ZiXunViewController: UIViewController {

    var product:ProductVo?
    let inputV = GCPlaceholderTextView()
    
    lazy var navView:UIView = {
        
        let bg = UIView()
        bg.backgroundColor = UIColor.white
        bg.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: HT_StatusBarAndNavigationBarHeight)
        let cancelBtn = UIButton()
        cancelBtn.setTitle("取消", for: .normal)
        cancelBtn.addTarget(self, action: #selector(cancelBtnClick), for: .touchUpInside)
        cancelBtn.setTitleColor(UIColor.textTitleColor, for: .normal)
        cancelBtn.titleLabel?.font = UIFont.commonFontSmaller
        bg.addSubview(cancelBtn)
        let _ = cancelBtn.sd_layout()?.leftSpaceToView(bg,16)!.heightIs(28)!.widthIs(38)!.topSpaceToView(bg,HT_StatusBarHeight+5)

        
        let titLab = UILabel()
        titLab.font = UIFont.titleFont
        titLab.text = "咨询"
        titLab.textColor = UIColor.black
        bg.addSubview(titLab)
        titLab.textAlignment = .center
        let _ = titLab.sd_layout()?.widthIs(60)!.heightIs(20)!.centerXEqualToView(bg)!.topSpaceToView(bg,HT_StatusBarHeight+5)

        
        
        let pubBtn = UIButton()
        bg.addSubview(pubBtn)
        let _ = pubBtn.sd_layout()?.widthIs(64)!.heightIs(28)!.topSpaceToView(bg,HT_StatusBarHeight+5)!.rightSpaceToView(bg,16)
        pubBtn.setTitle("提交", for: .normal)
        pubBtn.setTitleColor(UIColor.white, for: .normal)
        pubBtn.sd_cornerRadius = 14
        pubBtn.titleLabel?.font = UIFont.commonFontSmaller

        pubBtn.addTarget(self, action: #selector(pubBtnClick), for: .touchUpInside)
        pubBtn.gradientBtnMainColor()
        pubBtn.bringSubviewToFront(pubBtn.titleLabel!)
        
        
        
        return bg
    }()

    @objc func cancelBtnClick(){
        
        POP(vc: self)
    }
    @objc func pubBtnClick(){
        
        self.commitData()

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.backgroundColor

        self.view.addSubview(self.navView)
        let bg = UIView()
        bg.backgroundColor = UIColor.white
        view.addSubview(bg)
        let _ = bg.sd_layout()?.leftSpaceToView(view,0)!.rightSpaceToView(view,0)!.topSpaceToView(view,HT_StatusBarAndNavigationBarHeight+16)!.heightIs(190)
        inputV.font  = UIFont.commonFont
        inputV.textColor = UIColor.textTitleColorBlack
        inputV.placeholder = "请描述你要咨询的问题"
        inputV.placeholderColor = UIColor.textPlaceHolderColor
        bg.addSubview(inputV)
        let _ = inputV.sd_layout()?.leftSpaceToView(bg,16)!.rightSpaceToView(bg,16)!.topSpaceToView(bg,0)!.heightIs(190)
        inputV.backgroundColor = UIColor.white
        inputV.becomeFirstResponder()
        
        
    }
    
    func commitData() {
        
        if inputV.text.isEmpty == true{
            
            ToastUtil.show(msg: "请输入要咨询的问题")
            return
        }
        
        API.commitZiXun(params: [
                                 "pdtId":self.product!.id!,
                                 "remark":inputV.text!,
                                 "mobile":SPUtil.init().mobile
                                 ]) { (result) in
            
            
                                    ToastUtil.show(msg: "咨询问题已提交")
                                    POP(vc: self)
        }
        
    }

}
